function HandleManage(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;

  this._dirId = (options && options.d) ? options.d : 0;

  document._call = [];
  this._createElements();
};

HandleManage.prototype._createElements = function() {
  this._loadData();
};

HandleManage.prototype._loadData = function() {
  this._files = null;
  this._parents = null;
  this._retrieveFiles();
  this._retrieveParents();
};

HandleManage.prototype._verifyData = function() {
  if (this._files && this._parents) {
    this._updateElements();
  }
};

HandleManage.prototype._retrieveFiles = function() {
  var _self = this;
  new RequestUtils()._read('file', null, 'd.parentDirId=\'' + this._dirId + '\' AND d.customerTrackId=\'' + this._operator.trackId + '\'', null, null, null, null, function(result, params) { _self._files = result.data;
                                                                                                                                                                                              _self._verifyData.call(_self);
                                                                                                                                                                                            }, null);
};

HandleManage.prototype._retrieveParents = function() {
  var _self = this;
  new RequestUtils()._custom('retrieveFileRoot', { dirId: this._dirId, customerTrackId: this._operator.trackId }, function(result, params) { _self._parents = result;
                                                                                                                                             _self._verifyData.call(_self);
                                                                                                                                           }, null);
};

HandleManage.prototype._updateElements = function() {
  var _self = this; document._goods = [];
  DOMUtils.removeChildElements(this._gui.panel);
  DOMUtils.removeChildElements(this._gui.path);
  DOMUtils.removeChildElements(this._gui.status);
  
  /*--路径----*/
  var table = document.createElement('table');
  table.style.width = '900px';
  table.style.height = '32px';
  table.cellPadding = 0;
  table.cellSpacing = 0;
  this._gui.path.appendChild(table);
  tr = table.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.width = '90px';
  td.align = 'center';
  td.style.verticalAlign = 'middle';
  var home = document.createElement('img');
  home.src = 'image/manage/home.png';
  home.style.cursor='pointer';
  home.onclick = function() { location.href = '?t=manage&opts=' + MiscUtils.encode({ d: 0 }); };
  td.appendChild(home);
  
  td = tr.insertCell(-1);
  td.style.width = '810px';
  td.align = 'left';
  var navitable = document.createElement('table');
  navitable.style.width = '810px';
  navitable.style.height = '32px';
  navitable.cellPadding = 0;
  navitable.cellSpacing = 0;
  td.appendChild(navitable);

  ntr = navitable.insertRow(-1);
  if (this._parents.length >= 4) {
    ntd = ntr.insertCell(-1);
    ntd.align = 'left';
    var table1 = document.createElement('table');
    table1.cellPadding = 0;
    table1.cellSpacing = 0;
    table1.style.width = '90px';
    ntd.appendChild(table1);
    tr1 = table1.insertRow(-1);
    td1 = tr1.insertCell(-1);
    td1.style.width = '11px';
    td1.align = 'left';
    td1.style.verticalAlign = 'middle';
    var narrow = document.createElement('img');
    narrow.src = 'image/manage/right.png';
    td1.appendChild(narrow);
    td1 = tr1.insertCell(-1);
    td1.style.width = '79px';
    td1.align = 'center';
    td1.style.verticalAlign = 'middle';
    td1.appendChild(document.createTextNode('......'));
    for(var i = 2, il = 0; i >= il; i--) {
      var parent = this._parents[i];
      ntd = ntr.insertCell(-1);
      ntd.align = 'left';
      var table1 = document.createElement('table');
      table1.cellPadding = 0;
      table1.cellSpacing = 0;
      table1.style.width = '90px';
      ntd.appendChild(table1);
      tr1 = table1.insertRow(-1);
      td1 = tr1.insertCell(-1);
      td1.style.width = '11px';
      td1.align = 'left';
      td1.style.verticalAlign = 'middle';
      var narrow = document.createElement('img');
      narrow.src = 'image/manage/right.png';
      td1.appendChild(narrow);
      td1 = tr1.insertCell(-1);
      td1.style.width = '79px';
      td1.align = 'center';
      td1.style.verticalAlign = 'middle';
      var a = document.createElement('a');
      a.href = '#';
      a._parent = parent;
      if (i != 0) {
        a.appendChild(document.createTextNode(NPFileUtils.cutStr(parent.name, 8)));
        a.onclick = function() { location.href = '?t=manage&opts=' + MiscUtils.encode({ d: this._parent.dirId }); };
        td1.appendChild(a);
      } else {
        td1.appendChild(document.createTextNode(NPFileUtils.cutStr(parent.name, 8)));
      }
    }
  } else {
    for(var i = this._parents.length-1, il = 0; i >= il; i--) {
      var parent = this._parents[i];
      ntd = ntr.insertCell(-1);
      ntd.align = 'left';
      var table1 = document.createElement('table');
      table1.cellPadding = 0;
      table1.cellSpacing = 0;
      table1.style.width = '90px';
      ntd.appendChild(table1);
      tr1 = table1.insertRow(-1);
      td1 = tr1.insertCell(-1);
      td1.style.width = '11px';
      td1.align = 'left';
      td1.style.verticalAlign = 'middle';
      var narrow = document.createElement('img');
      narrow.src = 'image/manage/right.png';
      td1.appendChild(narrow);
      td1 = tr1.insertCell(-1);
      td1.style.width = '79px';
      td1.align = 'center';
      td1.style.verticalAlign = 'middle';
      if (i != il) {
        var a = document.createElement('a');
        a.href = '#';
        a._parent = parent;
        a.appendChild(document.createTextNode(NPFileUtils.cutStr(parent.name, 8)));
        a.onclick = function() { location.href = '?t=manage&opts=' + MiscUtils.encode({ d: this._parent.dirId }); };
        td1.appendChild(a);
      } else {
        td1.appendChild(document.createTextNode(NPFileUtils.cutStr(parent.name, 8)));
      }
    }
  }
  ntd = ntr.insertCell(-1);
  ntd.style.width = '800px';
  
  /*--返回--*/
  this._gui.tools.back.onclick = function() { new RequestUtils()._read('file', null, 'd.dirId=\'' + _self._dirId + '\'' + ' AND d.customerTrackId=\'' + _self._operator.trackId + '\'', null, null, null, null, function(result, params) { if (result.data.length != 0) {
                                                                                                                                                                                                                                             _self._dirId = (result.data[0].parentDirId != 0) ? result.data[0].parentDirId : 0;
                                                                                                                                                                                                                                             location.href = '?t=manage&opts=' + MiscUtils.encode({ d: _self._dirId });
                                                                                                                                                                                                                                           }
                                                                                                                                                                                                                                         }, null);
                                            };

  this._gui.tools.back.style.display = (this._dirId) ? 'block' : 'none';

  var iframe = document.createElement('iframe');
  iframe.style.width = '100%';
  iframe.style.height = '100%';
  iframe.frameBorder = 0;
  iframe.style.overflowY = 'auto';
  iframe.style.overflowX = 'hidden';
  iframe.src = '?b=baseblank&t=directory&opts=' + MiscUtils.encode({ d: this._dirId });
  this._gui.panel.appendChild(iframe);
  
  
  var func = function() { _self._retrieveFiles.call(_self); };
  document._call[0] = { func: func };

  var span = document.createElement('span');
  span.style.color = '#0000ff';
  span.appendChild(document.createTextNode(this._files.length));
  this._gui.status.appendChild(span);
  this._gui.status.appendChild(document.createTextNode(' object' + ((this._files.length == 0) ? '' : 's')));
  
  
  this._gui.tools.newFolder.onclick = function() { var name = window.prompt('FILE NAME', '');
                                                   if (name && name != '') {
                                                     if (NPFileUtils.duplicates(_self._files, name)) {
                                                       window.alert('DUPLICAED NAME');
                                                       return;
                                                     }
//                                                     if (NPFileUtils.limitLNP(name)) {
//                                                       window.alert('Only Allow Letters, Numbers Or Decimal Point');
//                                                       return;
//                                                     }
                                                     var file = File.instance();
                                                     file.customerTrackId = _self._operator.trackId;
                                                     file.parentDirId = _self._dirId;
                                                     file.name = name;
                                                     var arr = [];
                                                     arr = name.split('.');
                                                     file.dirId = (arr.length == 1) ? MiscUtils.unique() : '';
                                                     file.trueName = (arr.length == 1) ? '' : MiscUtils.unique() + '.' + arr[arr.length-1];
                                                     new RequestUtils()._custom('create', { file: file }, function(result, params) { if (result) { _self._retrieveFiles.call(_self); } }, { pos: DOMUtils.findPos(this) });
                                                   } else if (name == '') {
                                                     window.alert('CAN NO BE EMPTY');
                                                   }
                                                 };

  this._gui.tools.remove.onclick = function () { if (document._goods.length == 0) {
                                                   window.alert('NO SELECTED FILES');
                                                   return;
                                                 }
                                                 var confirm = window.confirm('CONFIRM DELETE?');
                                                 if (confirm) {
                                                   new RequestUtils()._custom('delete', { files: document._goods }, function(result, params) { if (result) { _self._retrieveFiles.call(_self); } }, { pos: DOMUtils.findPos(this)});
                                                 }
                                               };
  this._gui.tools.copyTo.onclick = function() { if (document._goods.length == 0) {
                                                 window.alert('NO SELECTED FILES');
                                                 return;
                                               }
                                               var pos = [window.screen.width / 3, window.screen.height / 3];
                                               var tmp = new ModulePopupBox(document, document.body, 476, 414, _self._operator, _self._now, { pos: pos, title: 'Copy To' });
                                               new ModuleCopyTo(document, tmp._gui.panel, 468, 414, _self._operator, _self._now, { callbackFunc: function() { _self._retrieveFiles.call(_self); }, selected: document._goods, popupBox: tmp });
                                             };
  this._gui.tools.moveTo.onclick = function() { if (document._goods.length == 0) {
                                                  window.alert('NO SELECTED FILES');
                                                  return;
                                                }
                                                var pos = [window.screen.width / 3, window.screen.height / 3];
                                                var tmp = new ModulePopupBox(document, document.body, 476, 414, _self._operator, _self._now, { pos: pos, title: 'Move To' });
                                                new ModuleMoveTo(document, tmp._gui.panel, 468, 414, _self._operator, _self._now, { callbackFunc: function() { _self._retrieveFiles.call(_self); }, selected: document._goods, popupBox: tmp });
                                              };

  this._gui.upload.onclick = function() { var pos = [window.screen.width / 3, window.screen.height / 3];
                                          var tmp = new ModulePopupBox(document, document.body, 476, 260, _self._operator, _self._now, { pos: pos, title: 'Upload' });
                                          new ModuleUpload(document, tmp._gui.panel, 468, 260, _self._operator, _self._now, { callbackFunc: function() { _self._retrieveFiles.call(_self); }, popupBox: tmp, dirId: _self._dirId });
                                        };
  
  this._gui.download.onclick = function() { if (document._goods.length == 0) {
                                              window.alert('NO SELECTED FILES');
                                              return;
                                            }
                                            //window.open('download1.php?action=' + MiscUtils.encode({files: document._goods }), '_blank');
                                          }
};

